/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package master.committee;

import common.SystemVariyable;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import master.committee.object.Privilages;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Transaction;
import template.RegistrantionPanel;

/**
 *
 * @author iagz pc
 */
public class PCCommittee extends RegistrantionPanel {

    /**
     * Creates new form PCCustomer1
     */
    public PCCommittee() {
        initComponents();
        initOthers();
    }

    private Object[] getPrivilage() {
        Transaction transaction = SystemVariyable.session.beginTransaction();
        try {
            String hql = "from master.committee.object.Privilages";
            Query query = SystemVariyable.session.createQuery(hql);
            List list = query.list();
            transaction.commit();
            Object[] objects = list.toArray(new Object[list.size()]);
            return objects;
        } catch (HibernateException e) {
            return null;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void initOthers() {
        object = new master.committee.object.Committee();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtCode = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtNoOfMembers = new javax.swing.JFormattedTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaDescription = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        cboPrivilage = new javax.swing.JComboBox();
        sSelectBox1 = new component.display_component.sSelectBox();

        jLabel4.setText("Privilage :");

        jLabel2.setText("Name :");

        jLabel5.setText("No of Members :");

        jLabel1.setText("Code :");

        txtNoOfMembers.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        txaDescription.setColumns(20);
        txaDescription.setRows(3);
        jScrollPane1.setViewportView(txaDescription);

        jLabel6.setText("Description :");

        cboPrivilage.setModel(new javax.swing.DefaultComboBoxModel(getPrivilage()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel1)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sSelectBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(txtName)
                    .addComponent(cboPrivilage, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCode, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNoOfMembers, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cboPrivilage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtNoOfMembers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sSelectBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cboPrivilage;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private component.display_component.sSelectBox sSelectBox1;
    private javax.swing.JTextArea txaDescription;
    private javax.swing.JTextField txtCode;
    private javax.swing.JTextField txtName;
    private javax.swing.JFormattedTextField txtNoOfMembers;
    // End of variables declaration//GEN-END:variables
    private static master.committee.object.Committee object;

    @Override
    public List<Component> getIdentityComponent() {
        return Arrays.asList(
                (Component) txtCode
        );
    }

    @Override
    public List<Component> getEsentialComponent() {
        return Arrays.asList(
                (Component) txtName
        );
    }

    @Override
    public List<Component> getOtherComponent() {
        return Arrays.asList(
                (Component) cboPrivilage,
                (Component) txtNoOfMembers,
                (Component) txaDescription
        );
    }

    @Override
    public Object initObject() {
        object.setCode(txtCode.getText());
        object.setName(txtName.getText());
        object.setPrivilages((Privilages) cboPrivilage.getSelectedItem());
        object.setNumberOfMembers(Integer.parseInt(txtNoOfMembers.getText()));
        object.setDescription(txaDescription.getText());

        return object;
    }

    @Override
    public void getUnbindObject(Object object) {
    }

    @Override
    public void bindComponents(ArrayList<Object> list, int index) {
        object = (master.committee.object.Committee) list.get(index);

        txtCode.setText(object.getCode());
        txtName.setText(object.getName());
        cboPrivilage.setSelectedItem(object.getPrivilages().toString());
        txtNoOfMembers.setText(object.getNumberOfMembers().toString());
        txaDescription.setText(object.getDescription());

    }

    @Override
    public List<Component> componentList() {
        return Arrays.asList(
                (Component) txtCode,
                (Component) txtName,
                (Component) cboPrivilage,
                (Component) txtNoOfMembers,
                (Component) txaDescription
        );
    }
}
